import { Delete, Get, Patch, Post } from '@/utils/http'
import type { ApiResponse } from 'axios'

export function getWorks<T>(params: {}, config: { opName: string }): ApiResponse<T> {
  return Get<T>('/api/works/list', params, config)
}
export function getTemplates<T>(params: {}, config: { opName: string }): ApiResponse<T> {
  return Get<T>('/api/works/templist', params, config)
}

export function createWork<T>(payload: {}, config: { opName: string }): ApiResponse<T> {
  return Post<T>('/api/works/create', payload, config)
}

export function copyWork<T>(id: number, config: { opName: string }): ApiResponse<T> {
  return Post<T>(`/api/works/copy/${id}`, {}, config)
}

export function saveWork<T>(id: string, payload: {}, config: { opName: string }): ApiResponse<T> {
  return Patch<T>(`/api/works/update/${id}`, payload, config)
}

export function getWork<T>(id: number, config: { opName: string }): ApiResponse<T> {
  return Get<T>(`/api/works/${id}`, config)
}

export function publishWork<T>(
  id: string,
  payload: {},
  config: { opName: string }
): ApiResponse<T> {
  return Patch<T>(`/api/works/publish/work/${id}`, payload, config)
}

export function publishTemplate<T>(
  id: string,
  payload: {},
  config: { opName: string }
): ApiResponse<T> {
  return Patch<T>(`/api/works/publish/template/${id}`, payload, config)
}

export function getWorkChannels<T>(id: string, config: { opName: string }): ApiResponse<T> {
  return Get<T>(`/api/works/channels/${id}`, config)
}

export function createWorkChannels<T>(payload: {}, config: { opName: string }): ApiResponse<T> {
  return Post<T>(`/api/works/channels`, payload, config)
}

export function deleteWorkChannel<T>(id: string, config: { opName: string }): ApiResponse<T> {
  return Delete<T>(`/api/works/channels/delete/${id}`, config)
}
export function deleteWork<T>(id: number, config: { opName: string }): ApiResponse<T> {
  return Delete<T>(`/api/works/delete/${id}`, config)
}

export const WorkApi = {
  getWorks,
  createWork,
  getWork,
  saveWork,
  publishWork,
  getWorkChannels,
  createWorkChannels,
  deleteWorkChannel,
  publishTemplate,
  getTemplates,
  deleteWork,
  copyWork
}
